package com.monitor.util.command;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class UnixCommand implements ISysCommand {

	private String commandStr;//命令字符串
	private List<String> lineStrList ;
	
	public UnixCommand(){
		
	}
	
	public UnixCommand(String commandStr){
		this.commandStr = commandStr;
	}
	
	@Override
	public void excute() throws Exception {
		Runtime runComm =Runtime.getRuntime();  
		runComm.exec(this.commandStr); 
	}

	public void setCommandStr(String commandStr) {
		this.commandStr = commandStr;
	}

	@Override
	public List<String> getLineStrList() throws Exception {
		lineStrList = new ArrayList<String>();
		Runtime runComm =Runtime.getRuntime();  
		Process ps = runComm.exec(this.commandStr); 
	    
	    BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
	    String line;
	    while ((line = br.readLine()) != null) {
	    	lineStrList.add(line);
	    }
		return lineStrList;
	}
	
	
}
